<?php
if ( count( get_included_files() ) == 1 ) die( '---' );

class DroitCompetence
{
	var $droitId;
	
	var $competenceId;

	var $tableDroitCompetence;

	
    // Constructeur
    function DroitCompetence() 
    {
    	$this->droitId = '';
    	$this->competenceId = '';

	
	global $C2IPRATtables;    	
	$this->tableDroitCompetence = $C2IPRATtables['C2IPRATdroitsCompetence'];
    }
    
    // Load 
    function load($entreeId,$competenceId)
    {
 
    	$sql = "SELECT *
		FROM `".$this->tableDroitCompetence."`
		WHERE droitId = '".$droitId."'
		AND competenceId = '".$competenceId."'";
		$data = claro_sql_query_get_single_row($sql);

	   if( !empty($data) )
	   {
	   	$this->droitId     		= $data['droitId'];
	   	$this->competenceId      	= $data['competenceId'];
	   	
	   	return true;
	   }
	   else
	   return false;
    }
    
    
    // Save 
    function save()  
    {
		$this->delete();

    		$sql = "INSERT INTO `".$this->tableDroitCompetence."` 
			SET droitId = '".$this->droitId."',
			    competenceId = '".$this->competenceId;
			// execute the creation query and get id of inserted assignment

		    if(claro_sql_query($sql))
		    {
		      	return true;
		    }
		    else
		    {
		        return false;
		    }
    }
    
    	 function delete()
	 {
	 	$sql = "DELETE FROM `".$this->tableDroitCompetence."` WHERE droitId = '".$this->droitId."'
		AND competenceId = '".$this->competenceId."'";

	 	if( claro_sql_query($sql) == false ) return false;
		return true;
	 }
	
	
	
	/**
     * get id
     *
     * @author Pierre Raynaud
     * @return int
     */
	function getDroitId()
	{
		return (int) $this->droitId;
	}

     /**
     * set id
     *
     * @author Pierre Raynaud
     * @return int
     */
	function setDroitId($value)
	{
		$this->droitId = (int) $value;
	}
	
	
	/**
     * get competenceId
     *
     * @author Pierre Raynaud
     * @return string
     */
	function getCompetenceId()
	{
		return $this->competenceId;
	}
	
	/**
     * set competenceId
     *
     * @author Pierre Raynaud
     * @param string $value
     */
	function setCompetenceId($value)
	{
		$this->competenceId = (int) $value;
	}
}
?>
